# Maintainer: Pierre Schmitz <pierre@archlinux.de>
# Contributor: Alexandre Bique <bique.alexandre@gmail.com>

pkgname=hefur
pkgver=1.0
pkgrel=11
pkgdesc='A standalone and lightweight BitTorrent tracker'
arch=('loong64' 'x86_64')
url='https://github.com/abique/hefur'
license=('MIT')
makedepends=('git' 'cmake')
depends=('gnutls' 'xz' 'protobuf')
source=("git+https://github.com/abique/${pkgname}.git#tag=${pkgver}"
        'hefurd.service' 'tmpfiles.conf' 'sysusers.conf'
        'protobuf-23.patch')
sha256sums=('SKIP'
            '3d8b0a716f35798f6aa25d6ee6a032d8a142811b920338bcb398c24beb1c8b43'
            '7d39eec7c9f004a8651de95d11d32422f0a506f0fe21d5fdf37a407a05d4de0f'
            'e265b34eff94197c33a1409191aa75812f099b3638f8877db3d2d43bf0decc19'
            '608a0422c80ac4c6d399ac0d7b0d27c34b436b9d4bd31f32e3ccbb678f1d0ffa')

prepare() {
	cd "${srcdir}/${pkgname}"
	git submodule set-url mimosa https://github.com/abique/mimosa.git
	git submodule init
	git submodule update
	sed -i "s/PROJECT_NUMBER.*/PROJECT_NUMBER=${pkgver}/g" Doxyfile
	sed -i "s/tracker-controller.hh//g" hefur/CMakeLists.txt

        patch -d mimosa -p1 -i "$srcdir"/protobuf-23.patch # Fix build with protobuf 23
}

build() {
	cd "${srcdir}/${pkgname}"
	mkdir build
	cd build
	cmake -DCMAKE_INSTALL_PREFIX=/usr ..
	make
}

package() {
	cd "${srcdir}/${pkgname}/build"
	DESTDIR="${pkgdir}" make install
	install -D -m644 "${srcdir}/hefurd.service" "${pkgdir}/usr/lib/systemd/system/hefurd.service"
	install -D -m644 "${srcdir}/tmpfiles.conf" "${pkgdir}/usr/lib/tmpfiles.d/hefurd.conf"
	install -D -m644 "${srcdir}/sysusers.conf" "${pkgdir}/usr/lib/sysusers.d/hefurd.conf"
	install -D -m644 "${srcdir}/${pkgname}/LICENSE.md" "${pkgdir}/usr/share/licenses/hefur/LICENSE"
}
